package com.example.homeworkservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.homeworkservice.entity.homework_submit;
import com.example.homeworkservice.mapper.homeworkSubmitMapper;
import com.example.homeworkservice.service.homeworkSubmitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class homeworkSubmitServiceImpl extends ServiceImpl<homeworkSubmitMapper, homework_submit> implements homeworkSubmitService {
    
    @Autowired
    private homeworkSubmitMapper homeworkSubmitMapper;
    
    @Override
    public List<Map<String, Object>> getStudentSubmissions(int userId) {
        return homeworkSubmitMapper.getStudentSubmissions(userId);
    }
    
    @Override
    public List<Map<String, Object>> getHomeworkSubmissions(int homeworkId) {
        return homeworkSubmitMapper.getHomeworkSubmissions(homeworkId);
    }
    
    @Override
    public homework_submit getStudentHomeworkSubmission(int userId, int homeworkId) {
        LambdaQueryWrapper<homework_submit> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(homework_submit::getUser_id, userId)
                   .eq(homework_submit::getHomework_id, homeworkId);
        return getOne(queryWrapper);
    }
    
    @Override
    public List<Map<String, Object>> getStudentHomeworks(int userId) {
        return homeworkSubmitMapper.getStudentHomeworks(userId);
    }
}
